<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #allmap{height:100%}
    </style>

    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <script src="/resources/js/jquery.min.js"></script>
</head>
<body>
<input type="hidden" id="kaishi">
<input type="hidden" id="jieshu">

    <div id="allmap"></div>
</body>
</html>
<script>
    var kaishi=null;
    var jieshu=null;
</script>
<script type="text/javascript">

    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
    // 百度地图API功能
    map.enableScrollWheelZoom(true);
   /* setTimeout(function(){
        $("#kaishi").val("河北省衡水市衡水职业技术学院");
        $("#jieshu").val("河北省邯郸市永年县");
    },5000);*/
   var time=setInterval(function(){
       kaishi=$("#kaishi").val();
       jieshu=$("#jieshu").val();
       if(kaishi!=null && kaishi!=''){
           $(".anchorBL").remove();
            jisuan();
            clearInterval(time);
       }
   },100);

</script>
<script>
    function jisuan(){
        var start = kaishi;
        var end = jieshu;
        var output = "从上地到西单驾车需要";
        var searchComplete = function (results){
            if (transit.getStatus() != BMAP_STATUS_SUCCESS){
                return ;
            }
            var plan = results.getPlan(0);
            output += plan.getDuration(true) + "\n";                //获取时间
            output += "总路程为：" ;
            output += plan.getDistance(true) + "\n";             //获取距离
        }
        var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
            onSearchComplete: searchComplete,
            onPolylinesSet: function(){
                setTimeout(function(){
                    //alert(output);
                    parent.layer.msg(output);
                },500);
            }});
        transit.search(kaishi, jieshu);
    }
</script>